djinnifandomcom-20200222-history
The witcher and his equipment
Category:Scripts A rather important element when creating a module is to define Geralt’s equipment. Unfortunately, this isn’t really simple. To make this work, we have to create a script which will help to define Geralt’s equipment. This time, we’ll create one through the File menu by choosing New -> Neverwinter Script (.nss): The new neverwinternights script window will appear: First, type in a comment to label the script: The function that we’ll use to create Geralt’s equipment is called CreateItemOnObject. One of the arguments we need to define is the object that’s going to be assigned to the item. In our case it’s Geralt. This is done with the help of the GetFirstPC function. First, though, we’ll add another comment to make our script clearer: Then add the following in the line with the GetFirstPC function: The line can be read as follows: draw on the object of the first player and assign it to the oPC object. Now it’s time to employ the equipment creating function. In the CreateItemOnObject function we need to define the name of the item’s template. All item templates are saved in the Data\Templates\Items folder. As an example, let’s add a couple of orens (the currency used in The Witcher) and a silver sword (a steel sword is added by default so we don’t need to worry about that) to Geralt’s equipment. The oren templates have names ranging from it_gold_001.uti to it_gold_014.uti. These templates are saved in the Data\Templates\Items\Valuables folder. The template for the silver sword is called it_svswd_004.uti and is saved in the Data\Templates\Items\Weapons&Armor folder. Keep in mind that in the CreateItemOnObject function the template names need to be written without the .uti extension. Let’s get back to our script. First, let’s type in the CreateItemOnObject function, opening with a ‘(‘: A tip regarding the function’s arguments has appeared. Following the item template and object target, the last argument that we need to determine in the CreateItemOnObject function is the quantity of the item. This is the number of objects of the same template that are to be created. Type in the whole line: Remember to end with a ‘;’. Now let’s add an additional comment, though in a different place than usual: As you can see, we can write comments at the end of a line. You can’t do this at the beginning of a line, however, at least not using the ‘//’ symbols. If really you want to add a comment at the beginning of a line (which isn’t recommended as it clutters the scripting), it can be done using the ‘/*’ ‘*/’ comment type. The above line can be read like this: add 50 items, based upon the it_gold_005 template, to the oPC object. Now add the silver sword: That’s it, our script is ready. Now save it by choosing Save As… in the File menu: This opens the standard Windows window used for saving files. Go to the Data\Scripts folder (where all scripts are saved), name it equipment and click Save. Remember that the name of the file cannot exceed 16 characters. Make sure the file is saved in the .nss format: If a different type of file is listed instead, it probably means that you’re trying to save the content in another open window by accident. Before saving, make sure that the new neverwinternights script window is active. If it is inactive, the title bar will be grey: A different color means that the window is active: An asterisk before the name in the title bar means that the file has not been saved since the last change was introduced. Remember that the script can be saved directly to the module. To do this, choose Save new neverwinternights scripts in the File menu and select Module in the new Save File window that appears. In this manual, we haven’t been using this method, preferring to save globally and then manually add files to modules using the Resources Explorer. This method has been discussed in one of the previous chapters. Now check the Aurora log to see whether the saving and compilation of the script was successful: The first entry means that the saving process was successful, while the second entry shows that the compilation took place without errors, as well. The third entry is a subsequent save. Now let’s add our script to the module. The best way to do this is to assign the script to the On Client Enter event in the Module Properties. This way, the script will be launched whenever Geralt appears in the module. Load the module, if it hasn’t been loaded yet, and open the Module Explorer. To do this, choose Utility Windows -> Module Explorer in the View menu: In the Module Explorer window, double-click Module Properties: The Properties window containing the module’s attributes will appear. Click the small yellow icon in the right-hand column opposite the On client enter attribute: This opens the standard Windows window used for loading files. Go to the Data\Scripts folder (where the script is saved), select equipment.nss and click Open. This will assign the equipment.nss script to the On client enter action: All that’s left now is to save the entire module. To do this, select Save Module from the Module menu: Upon loading of the module, Geralt will now have 50 orens and a silver sword. The method of adding equipment described in this chapter can be used to determine other characters’ equipment as well.d